home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python152_Src.lha / Python152_Source / Amiga / dosio_init.c < prev    next >
C/C++ Source or Header  |  1998-02-01  |  3KB  |  107 lines

  1. RCS_ID_C="$Id: dosio_init.c,v 4.2 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      dosio_init.c - SAS C auto initialization functions for DOSIO
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <exec/execbase.h>
  11. extern struct ExecBase *SysBase;
  12.  
  13. #include <dos/dos.h>
  14. #include <dos/dosextens.h>
  15.  
  16. #if __SASC
  17. #include <proto/dos.h>
  18. #elif __GNUC__
  19. #include <inline/dos.h>
  20. #else
  21. #include <clib/dos_protos.h>
  22. #endif
  23.  
  24. #include <constructor.h>
  25.  
  26.  
  27. /****** netd.lib/dosio_init *********************************************
  28.  
  29.     NAME
  30.         dosio_init - (std) io macros to dos.library V37 or newer
  31.  
  32.     SYNOPSIS
  33.         long _STI_500_dosio_init(void)
  34.  
  35.     FUNCTION
  36.         This function initializes the file table used by the stdio
  37.         look-a-like macros defined in <netinclude:stdio.h>.
  38.  
  39.         These macros are taken in to use by defining the symbol
  40.         `USE_DOSIO' before including any include files.  When this is
  41.         done, the normal stdio prototypes are replaced with macros,
  42.         which call the corresponding dos.library functions.  The
  43.         netd.lib provides the initialization function mentioned above
  44.         and the functions VSPrintf(), SPrintf(), VCSPrintf() and
  45.         CSPrintf(), which are not found from the dos.library.
  46.  
  47.         The stdio macros provided are suitable for stdin, stdout and
  48.         stderr usage. No file opening function (fopen()) is provided,
  49.         so the use is quite limited.
  50.  
  51.         The netd.lib version of the net.lib is compiled with this
  52.         USE_DOSIO, so you will want to use that instead of the
  53.         net.lib to make your executable smaller if your own program
  54.         does not use stdio of the C runtime library.
  55.  
  56.     NOTES
  57.         The stdio macros rely on dos.library 37 or newer being present.
  58.  
  59.         The autoinitialization and autotermination functions are features
  60.         specific to the SAS C6.  However, these functions can be used with
  61.         other (ANSI) C compilers, too. Example follows:
  62.  
  63.         \* at start of main() *\
  64.  
  65.         if (_STI_500_dosio_init() != 0)
  66.        exit(20);
  67.  
  68.     BUGS
  69.         The same autoinitialization won't work for both SAS C 6.3 and SAS C
  70.         6.50 or latter.  Only way to terminate an initialization function is
  71.         by exit() call with SAS C 6.3 binary.  If an autoinitialization
  72.         function is terminated by exit() call with SAS C 6.50 binary, the
  73.         autotermination functions won't be called.  Due this braindamage
  74.         the libraries must be separately compiled for each compiler version.
  75.  
  76.     SEE ALSO
  77.  
  78.  
  79. *****************************************************************************
  80. */
  81.  
  82. BPTR __dosio_files[3];
  83.  
  84. /*
  85.  * Using __stdargs prevents creation of register arguments entry point.
  86.  * If both stack args and reg. args entry points are created, this
  87.  * function is called _twice_, which is not wanted.
  88.  *
  89.  * The number 500 in the function names is the priority assigned to
  90.  * stdio autoinitialization functions by SAS/C 6.50.
  91.  */
  92. // long __stdargs
  93. // _STI_500_dosio_init(void)
  94. STDIO_CONSTRUCTOR(dosio_init)
  95. {
  96.   struct Process *p = (struct Process *)SysBase->ThisTask;
  97.  
  98.   __dosio_files[0] = p->pr_CIS;    /* stdin */
  99.   __dosio_files[1] = p->pr_COS;    /* stdout */
  100.   __dosio_files[2] = p->pr_CES;    /* stderr */
  101.  
  102.   if (__dosio_files[2] == 0)
  103.     __dosio_files[2] = __dosio_files[1];
  104.  
  105.   return 0;
  106. }
  107.